package com.han.school.service.impl;

import com.han.school.mapper.AchievementsMapper;
import com.han.school.pojo.Achievements;
import com.han.school.service.AchiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AchiServiceImpl implements AchiService {
    @Autowired
    private AchievementsMapper achievementsMapper;

    @Override
    public String insert(Achievements record) {
        List<Achievements> achievements = achievementsMapper.selectByMonth(record.getMonth());
        for (Achievements a1:achievements
             ) {
            if (a1.getTname().equals(record.getTname())&&a1.getMonth().equals(record.getMonth())){
                achievementsMapper.update(record);
                return a1.getTname()+"这个月已经有成绩了,执行覆盖";
            }
        }
        int insert = achievementsMapper.insert(record);
        return "添加成功";
    }

    @Override
    public List<Achievements> selectByMonth(Integer month) {
        return achievementsMapper.selectByMonth(month);
    }

    @Override
    public int update(Achievements record) {
        int update = achievementsMapper.update(record);
        return update;
    }
}
